package kr.hkit.powerjava.chapter15;

import javax.swing.JColorChooser;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ChangePanel<JcolorChooser> extends JPanel implements ActionListener {
	private JButton btnChangeColor;
	private Color color;
	private JcolorChooser choose;
	/**
	 * Create the panel.
	 */
	public ChangePanel() {

		initialize();
	}
	private void initialize() {
		setLayout(new BorderLayout(0, 0));
		color= new Color(0, 0, 0);//기본 값(블랙)
		btnChangeColor = new JButton("색상변경");
		btnChangeColor.addActionListener(this);
		add(btnChangeColor, BorderLayout.SOUTH);
	}
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(color);
		g.fillRect(10, 10, 430, 280);//채우기
		//color= new Color((int)(Math.random()*255.0), (int)(Math.random()*255.0), (int)(Math.random()*255.0));
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnChangeColor) {
			actionPerformedBtnChangeColor(e);
		}
	}
	protected void actionPerformedBtnChangeColor(ActionEvent e) {
		color= new Color((int)(Math.random()*255.0), (int)(Math.random()*255.0), (int)(Math.random()*255.0));
		repaint();
	}
}
